<?php
namespace app\index\controller;
use think\Controller;
use think\Db;
use think\Session;
class Browse extends Controller{
    /****
     Class register     商品收藏
     *@
    */
    public function browse(){
        $post = input('post.');
        $data = [
          'user_id'=>$post['user_id'],
          'goods_id'=>$post['goods_id'],
          'addtime'=>time(),
        ];
        $browse_add = Db::name('browse')->insert($data);
        $browse = Db::name('browse')
                  ->where(['user_id'=>$post['user_id']])
                  ->count();
        if($browse > 15){
          $browse_find = Db::name('browse')
                  ->where(['user_id'=>$post['user_id']])
                  ->find();
          Db::name('browse')->delete($browse_find['id']);
        }
        if($browse_add){
           $arr = [
               'state'     => 2,
               'message'   => "请求成功"
            ]; 
            return json($arr);
        }
    }  
}